import { getRandomSign } from '@/modules/genshin/creepSay'
import { ObserveTask } from './types'
import { goTo } from '@/modules/move'

/**
 * 签名任务
 */
export function signController(creep: Creep, task: ObserveTask) {
    const room = creep.room
    const controller = room.controller

    if (!controller) {
        task.done = true
        return
    }

    const { sign = getRandomSign() } = task.data

    if (controller.sign?.username === creep.owner.username && controller.sign?.text === sign) {
        task.done = true
        return
    }

    if (creep.pos.isNearTo(controller)) {
        const ok = creep.signController(controller, sign)
        if (ok === OK) {
            task.done = true
        }
    } else {
        goTo(creep, controller.pos)
    }
}
